import java.util.ArrayList;

/*
 * Amos Kittelson 
 * COP3503 - Computer Science 2
 * Assignment 3 - Railroad Building
 * Due 6 July 2010 (Extended due to military duty)
 */

public class Graph {

	// A Graph has Vertices that are connected by Edges
	ArrayList<Vertex> vertexs;
	ArrayList<Edge> edges;
	
	// Constructor
	public Graph(){
		vertexs = new ArrayList<Vertex>();
		edges = new ArrayList<Edge>();
	}
	
	// The size of the Graph is determined, in this case,
	// by the number of Edges in the Graph
	public int sizeOf(){
		return edges.size();
	}
	
	// If the vertex labels doesn't exist in the array
	// then add it and return null. Otherwise return the 
	// original Vertex object
	public Vertex addVertex(Vertex v){
		
		if (findVertex(v) == null){
			vertexs.add(v);
			return null;
		}
		return findVertex(v);
	}
	
	/*
	public int findVertexIndex(Vertex v){
		
		int index = 1;
		for (Vertex testv : vertexs){
			if (testv.getLabel() == v.getLabel())
				return index;
			index++;
		}
		return -1;	
	}
	*/
	
	// Look for a Vertex by label and return
	// the Vertex Object if its found
	private Vertex findVertex(Vertex v){
		
		for (Vertex testv : vertexs){
			if (testv.getLabel() == v.getLabel())
				return testv.getObject();
		}
		return null;	
	}
	
	// Add an Edge to the Graph
	public void addEdge(Edge e){
		edges.add(e);
	}
	
	// Return the Edge at index i
	public Edge getEdge(int i){
		return edges.get(i);
	}
	
	public ArrayList<Edge> returnArray(){
		return edges;
	}
	
}
